import {reactive, toRefs} from "vue";
import {get,post} from "./http"

export const useAjax = (def,v,handle)=>{
    let data = reactive({data:def,loading:false,err:null});
    data.loading = true;
    v.then((res)=>{
        if(handle){
            data.data = handle(res);
        }else{
            data.data = res;
        }
    }).catch((err)=>{
        data.err = err;
    }).finally(()=>{
        data.loading = false
    })

    return toRefs(data)
}


export const getProject = ()=>{
    return get("/api/project/list")
} 
export const addProject = (p)=>{
    return post("/api/project/add",p);
}

export const getIteration = (p)=>{
    return get("/api/iteration/list",p);
}

export const addIteration = (p)=>{
    return post("/api/iteration/add",p);
}


export const getSvg = (p)=>{
    return get("/api/svg/list",p);
}
export const addSvg = (p)=>{
    return post("/api/svg/add",p);
}
export const delSvg = (p)=>{
    return post("/api/svg/del",p);
}
export const updateSvg = (p)=>{
    return post("/api/svg/update",p);
}